import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { environment } from '@env/environment';
// layout
import { LayoutDefaultComponent } from '../layout/default/default.component';
import { LayoutPassportComponent } from '../layout/passport/passport.component';
// dashboard pages
import { DashboardComponent } from './dashboard/dashboard.component';
// passport pages
import { UserLoginComponent } from './passport/login/login.component';
import { UserRegisterComponent } from './passport/register/register.component';
import { UserRegisterResultComponent } from './passport/register-result/register-result.component';
// single pages
import { CallbackComponent } from './callback/callback.component';
import { UserLockComponent } from './passport/lock/lock.component';
import { Exception403Component } from './exception/403.component';
import { Exception404Component } from './exception/404.component';
import { Exception500Component } from './exception/500.component';
import { CurruserInfoComponent } from './curruser-info/curruser-info.component';
import { AuthGuard } from '@core/guards-activate/auth-guard.activate';
import { CanDeactivateGuard } from '@core/guards-activate/can-deactivate-guard.activate';
import { CanDeactivateVideoGuardActivate } from '@core/guards-activate/can-deactivate-video-guard.activate';
import { TriggerAuthGuardActivate } from '@core/guards-activate/trigger-auth-guard.activate';

const routes: Routes = [
  {
    path: '',
    component: LayoutDefaultComponent,
    canActivate: [AuthGuard],
    children: [
      { path: '', redirectTo: 'dashboard', pathMatch: 'full' },
      { path: 'dashboard', component: DashboardComponent, data: { title: '首页', titleI18n: '首页' } },
      { path: 'curr-user', component: CurruserInfoComponent, data: { title: '个人中心', titleI18n: '个人中心' } },
      { path: 'user', loadChildren: './user/user.module#UserModule' },
      // 业务子模块
      { path: 'company', loadChildren: './company/company.module#CompanyModule' },
      { path: 'application', loadChildren: './agent-application/agent-application.module#AgentApplicationModule' },
      { path: 'agent', loadChildren: './agent/agent.module#AgentModule' },
      { path: 'customer', loadChildren: './customer/customer.module#CustomerModule' },
      { path: 'order', loadChildren: './order/order.module#OrderModule' },
      { path: 'finances', loadChildren: './finances/finances.module#FinancesModule' },
      { path: 'goods', loadChildren: './goods/goods.module#GoodsModule' },
      { path: 'cars', loadChildren: './market-car/market-car.module#MarketCarModule' },
      { path: 'activity', loadChildren: './market-activity/market-activity.module#MarketActivityModule' },
      { path: 'market-agent', loadChildren: './market-agent/market-agent.module#MarketAgentModule' },
      { path: 'market-fans', loadChildren: './market-fans/market-fans.module#MarketFansModule' },
      { path: 'band', loadChildren: './market-band/market-band.module#MarketBandModule' },
      { path: 'mid-autumn', loadChildren: './mid-autumn/mid-autumn.module#MidAutumnModule' },
      { path: 'views', loadChildren: './operate-log/operate-log.module#OperateLogModule' },
      { path: 'banner', loadChildren: './banner/banner.module#BannerModule' },
      { path: 'salesman', loadChildren: './market-salesman/market-salesman.module#MarketSalesmanModule' },
      { path: 'performance', loadChildren: './agent-performance/agent-performance.module#AgentPerformanceModule' },
      { path: 'sys', loadChildren: './sys-param/sys-param.module#SysParamModule' },
      { path: 'img-material', loadChildren: './img-material/img-material.module#ImgMaterialModule' },
      { path: 'integral', loadChildren: './integral/integral.module#IntegralModule' },
      { path: 'fund-flow', loadChildren: './fund-flow/fund-flow.module#FundFlowModule' },
      { path: 'profit-withdraw', loadChildren: './profit-withdraw/profit-withdraw.module#ProfitWithdrawModule' },
      { path: 'otc-cus', loadChildren: './otc-cus/otc-cus.module#OtcCusModule' },
      { path: 'otc-convert', loadChildren: './otc-convert/otc-convert.module#OtcConvertModule' },
      { path: 'otc-shop', loadChildren: './otc-shop/otc-shop.module#OtcShopModule' },
      { path: 'service-cus', loadChildren: './service-cus/service-cus.module#ServiceCusModule' },
      { path: 'market-moments', loadChildren: './market-moments/market-moments.module#MarketMomentsModule' },
      { path: 'otc-center', loadChildren: './otc-center/otc-center.module#OtcCenterModule' },
      { path: 'otc-credit', loadChildren: './otc-credit/otc-credit.module#OtcCreditModule' },
      { path: 'otc-message', loadChildren: './otc-message/otc-message.module#OtcMessageModule' },
      { path: 'otc-rule-template', loadChildren: './otc-rule-template/otc-rule-template.module#OtcRuleTemplateModule' },
      {
        path: 'market-trigger',
        loadChildren: './market-trigger/market-trigger.module#MarketTriggerModule',
        canActivate: [TriggerAuthGuardActivate],
      },
    ],
  },
  // passport
  {
    path: 'passport',
    component: LayoutPassportComponent,
    children: [
      { path: 'login', component: UserLoginComponent, data: { title: '登录' } },
      { path: 'register', component: UserRegisterComponent, data: { title: '注册' } },
      {
        path: 'register-result',
        component: UserRegisterResultComponent,
        data: { title: '注册结果' },
      },
    ],
  },
  // 单页不包裹Layout
  { path: 'callback/:type', component: CallbackComponent },
  { path: 'lock', component: UserLockComponent, data: { title: '锁屏' } },
  { path: '403', component: Exception403Component },
  { path: '404', component: Exception404Component },
  { path: '500', component: Exception500Component },
  { path: '**', redirectTo: 'dashboard' },
];

@NgModule({
  imports: [RouterModule.forRoot(routes, { useHash: environment.useHash })],
  exports: [RouterModule],
  providers: [AuthGuard, CanDeactivateGuard, CanDeactivateVideoGuardActivate, TriggerAuthGuardActivate],
})
export class RouteRoutingModule {
}
